import 'package:flutter/cupertino.dart';
import 'package:flutter_demo/routers/names.dart';
import 'package:get/get.dart';

import '../../models/request/user_register_req.dart';
import '../../utils/encrypt.dart';

class RegisterLogic extends GetxController {
  // 表单key
  GlobalKey formKey = GlobalKey<FormState>();

  // 用户名
  TextEditingController userNameController = TextEditingController(text: "duxin");

  // 邮件
  TextEditingController emailController = TextEditingController(text: "duxindxo@gmail.com");

  // 姓
  TextEditingController firstNameController = TextEditingController(text: "duo");

  // 名
  TextEditingController lastNameController = TextEditingController(text: "xin");

  // 密码
  TextEditingController passwordController = TextEditingController(text: "12345678");

  // 注册
  void onSignUp() {
    if ((formKey.currentState as FormState).validate()) {
      // aes 加密密码
      var password = EncryptUtil().aesEncode(passwordController.text);

      //验证通过
      Get.offNamed(
        RouteNames.systemRegisterPin,
        arguments: UserRegisterReq(
          username: userNameController.text,
          email: emailController.text,
          firstName: firstNameController.text,
          lastName: lastNameController.text,
          password: password,
        ),
      );
    }
  }



  // 登录
  void onSignIn() {

  }


  @override
  void onClose() {
    super.onClose();
    userNameController.dispose();
    emailController.dispose();
    firstNameController.dispose();
    lastNameController.dispose();
    passwordController.dispose();
  }
}
